const send = require('koa-send'); 
var fn_hello = async (ctx, next) => {
 
};
var fn_download = async (ctx, next) => {
  var fileName = ctx.params.name;
  // ctx.response.body = `<h1>Hello, ${name}!</h1>`;
      // 为了方便演示，这里直接下载index页面
  // var fileName = 'index.html';
  // Set Content-Disposition to "attachment" to signal the client to prompt for download.
  // Optionally specify the filename of the download.
  // 设置实体头（表示消息体的附加信息的头字段）,提示浏览器以文件下载的方式打开
  // 也可以直接设置 ctx.set("Content-disposition", "attachment; filename=" + fileName);
  ctx.attachment(fileName);
  await send(ctx, fileName, { root: __dirname + '../../../../static' });
}

module.exports = {
  'GET /api/download/:name': fn_download
};